How to concatenate text from multiple rows into a single text string in SQL Server
How to concatenate text from multiple rows into a single text string in SQL Server
19815-Jul-2024
Updated on 15-Jul-2024
Home / DeveloperSection / Forums / How to concatenate text from multiple rows into a single text string in SQL Server
How to concatenate text from multiple rows into a single text string in SQL Server
Ashutosh Kumar Verma
15-Jul-2024You can contact multiple row values into a single text string value by using the SQL built-in function
STRING_AGG()
.Syntax-
The
STRING_AGG()
function requires 2 argument(s), the first one is the column name and the second one is a separater between values as you see in the above syntax.Example-
suppose we have a
Employees
table.Let's insert some values into above table,
As you can see in the below picture,
Example-
Now, use STRING_AGG() to concat multiple row values into a single string,
Also, Read: How to use searching and filtering data in an SQL server?